home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_548 / labelmaker / labelmakerv1.5.lzh / LabelLib.c < prev    next >
C/C++ Source or Header  |  1991-07-22  |  7KB  |  331 lines

  1. #include "LabelDef.h"
  2. #include <exec/memory.h>
  3. #include <libraries/dos.h>
  4.  
  5.  
  6. void
  7. ChangeCoords( The_Text, NewY)
  8. struct LabelText *The_Text;
  9. int NewY;
  10. {
  11.  if ( The_Text != NULL)
  12.    {
  13.     The_Text->TopEdge = NewY;
  14.    }
  15. }
  16.  
  17.  
  18.  
  19. void
  20. ChangeText( The_Text, FontName, Size, Style,
  21.             Align, Place, Border, BgCol, FgCol, Text, AttrNr)
  22. struct LabelText *The_Text;
  23. BYTE *FontName, *Text;
  24. int Size, Style, Align, Place, Border, BgCol, FgCol, AttrNr;
  25. {
  26.  int help;
  27.  
  28.  if ( The_Text != NULL)
  29.    {
  30.     help = Size +1;
  31.     if ( Border & LTB_TOP) help++;
  32.     if ( Border & LTB_BOTTOM) help++;
  33.     strncpy( &The_Text->FontName[0], FontName, 21);
  34.     strncpy( &The_Text->Text[0], Text, 61);
  35.     The_Text->AttrNumber = (LONG) AttrNr;
  36.     The_Text->FontSize   = (SHORT)(Size);
  37.     The_Text->Style      = (BYTE)(Style);
  38.     The_Text->Alignment  = (BYTE)(Align);
  39.     The_Text->Placement  = (BYTE)(Place);
  40.     The_Text->Border     = (BYTE)(Border);
  41.     The_Text->BgColor    = (BYTE)(BgCol);
  42.     The_Text->FgColor    = (BYTE)(FgCol);
  43.     The_Text->Width      = (SHORT)(help);
  44.    }
  45.  
  46. }
  47.  
  48.  
  49.  
  50. struct LabelText
  51. *CreateText( FontName, Size, Style, Align, Place, Border,
  52.              BgCol, FgCol, Text, AttrNr)
  53. BYTE *FontName, *Text;
  54. int Size, Style, Align, Place, Border, BgCol, FgCol, AttrNr;
  55. {
  56.  struct LabelText *HelpText;
  57.  
  58.  HelpText = NULL;
  59.  if (HelpText = AllocMem( sizeof( struct LabelText), MEMF_PUBLIC))
  60.    {
  61.     HelpText->PrevText   = NULL;
  62.     HelpText->NextText   = NULL;
  63.     ChangeText( HelpText, FontName, Size, Style,
  64.                 Align, Place, Border,  BgCol, FgCol, Text, AttrNr);
  65.     ChangeCoords( HelpText, 0);
  66.    }
  67.  return( HelpText);
  68. }
  69.  
  70.  
  71.  
  72. struct LabelText
  73. *DeleteText( The_Text)
  74. struct LabelText *The_Text;
  75. {
  76.  struct LabelText *Before, *After, *Back;
  77.  
  78.  Back = NULL;
  79.  if ( The_Text != NULL)
  80.    {
  81.     Before = The_Text->PrevText;
  82.     After  = The_Text->NextText;
  83.     if ( After != NULL)
  84.       {
  85.        After->PrevText = Before;
  86.        Back = After;
  87.       }
  88.     if ( Before != NULL)
  89.       {
  90.        Before->NextText = After;
  91.        Back = Before;
  92.       }
  93.     FreeMem( The_Text, sizeof( struct LabelText));
  94.    }
  95.  return( Back);
  96. }
  97.  
  98.  
  99.  
  100. struct LabelText
  101. *InsertText( Location, The_Text, Where)
  102. struct LabelText *Location, *The_Text;
  103. int Where;
  104. {
  105.  struct LabelText *Back, *Help;
  106.  
  107.  Back = NULL;
  108.  if (( Location != NULL)&&( The_Text != NULL)&&(Location != The_Text))
  109.    {
  110.     Back = The_Text;
  111.     if ( Where == 1)  /* before */
  112.       {
  113.        Help = Location->PrevText;
  114.        if ( Help != NULL) Help->NextText = The_Text;
  115.        Location->PrevText = The_Text;
  116.        The_Text->PrevText = Help;
  117.        The_Text->NextText = Location;
  118.       }
  119.     else              /* after */
  120.       {
  121.        Help = Location->NextText;
  122.        if ( Help != NULL) Help->PrevText = The_Text;
  123.        Location->NextText = The_Text;
  124.        The_Text->PrevText = Location;
  125.        The_Text->NextText = Help;
  126.       }
  127.    }
  128.  return( Back);
  129. }
  130.  
  131.  
  132.  
  133. struct LabelText
  134. *ReplaceText( The_Text, Dest_Text, Where)
  135. struct LabelText *The_Text, *Dest_Text;
  136. int Where;
  137. {
  138.  struct LabelText *Back, *Help, *Before, *After;
  139.  
  140.  Back = NULL;
  141.  if (( The_Text != NULL)&&(Dest_Text != NULL)&&(The_Text != Dest_Text))
  142.    {
  143.     Help = The_Text;
  144.     Before = Help->PrevText;
  145.     After  = Help->NextText;
  146.     if ( After != NULL)
  147.       {
  148.        After->PrevText = Before;
  149.       }
  150.     if ( Before != NULL)
  151.       {
  152.        Before->NextText = After;
  153.       }
  154.     Back = InsertText( Dest_Text, The_Text, Where);
  155.    }
  156.  return( Back);
  157. }
  158.  
  159.  
  160.  
  161. struct LabelText
  162. *FindStart( The_Text)
  163. struct LabelText *The_Text;
  164. {
  165.  struct LabelText *Back;
  166.  
  167.  Back = The_Text;
  168.  if ( Back != NULL)
  169.    {
  170.     while ( Back->PrevText != NULL)
  171.       {
  172.        Back = Back->PrevText;
  173.       }
  174.    }
  175.  return( Back);
  176. }
  177.  
  178.  
  179.  
  180. struct LabelText
  181. *FindEnd( The_Text)
  182. struct LabelText *The_Text;
  183. {
  184.  struct LabelText  *Back;
  185.  
  186.  Back = The_Text;
  187.  if ( Back != NULL)
  188.    {
  189.     while ( Back->NextText != NULL)
  190.       {
  191.        Back = Back->NextText;
  192.       }
  193.    }
  194.  return( Back);
  195. }
  196.  
  197.  
  198.  
  199. void
  200. DeleteAllTexts( Start)
  201. struct LabelText *Start;
  202. {
  203.  struct LabelText *Back, *Curr, *Begin;
  204.  int finished;
  205.  
  206.  if (Start != NULL)
  207.    {
  208.     Begin = FindStart( Start);
  209.     if (Begin != NULL)
  210.       {
  211.        finished =0;
  212.        while ( finished != 1)
  213.          {
  214.           Back = FindEnd( Begin);
  215.           if ( Back != Begin)
  216.             {
  217.              Curr = Back->PrevText;
  218.              FreeMem( Back, sizeof( struct LabelText));
  219.              if ( Curr != NULL)
  220.                {
  221.                 Curr->NextText = NULL;
  222.                }
  223.              else
  224.                {
  225.                 finished = 1;
  226.                }
  227.             }
  228.           else
  229.             {
  230.              finished =1;
  231.              if ( Begin != NULL) FreeMem( Begin, sizeof( struct LabelText));
  232.             }
  233.          }
  234.       }
  235.    }
  236. }
  237.  
  238.  
  239.  
  240.  
  241. struct LabelText
  242. *AddText( Root_Text, The_Text)
  243. struct LabelText *Root_Text, *The_Text;
  244. {
  245.  struct LabelText *Help_Text, *Back;
  246.  
  247.  Back = NULL;
  248.  if ((Root_Text != NULL)&&(The_Text != NULL)&&(Root_Text != The_Text))
  249.    {
  250.     Help_Text = FindEnd( Root_Text);
  251.     if ( Help_Text != NULL)
  252.       {
  253.        Back = InsertText( Help_Text, The_Text, 2);
  254.       }
  255.    }
  256.  return( Back);
  257. }
  258.  
  259.  
  260.  
  261. struct LabelText
  262. *LoadText( fh)
  263. struct FileHandle *fh;
  264. {
  265.  struct LabelText Bxt, *Back;
  266.  BYTE IDBuffer[5];
  267.  LONG LongBuffer;
  268.  LONG LabelTextSize;
  269.  int ok;
  270.  
  271.  Back = NULL;
  272.  LabelTextSize = sizeof( struct LabelText) -12;
  273.  if ((ok = Read( fh, IDBuffer, 4L)) == 4)
  274.    {
  275.     if ( strncmp( IDBuffer, "LMTC", 4) ==0)
  276.       {
  277.        ok = Read( fh, &LongBuffer, 4L);
  278.        if ((ok == 4)&&(LongBuffer == LabelTextSize))
  279.          {
  280.           ok = Read( fh, &Bxt, LabelTextSize);
  281.           if ( ok == LabelTextSize)
  282.             {
  283.              Back = CreateText( Bxt.FontName, Bxt.FontSize, Bxt.Style,
  284.                                 Bxt.Alignment, Bxt.Placement, Bxt.Border,
  285.                                 Bxt.BgColor, Bxt.FgColor, Bxt.Text, 0);
  286.              if ( Back != NULL)
  287.                {
  288.                 ChangeCoords( Back, Bxt.TopEdge);
  289.                }
  290.             }
  291.          }
  292.       }
  293.    }
  294.  return( Back);
  295. }
  296.  
  297.  
  298.  
  299. int
  300. SaveText( fh, The_Text)
  301. struct FileHandle *fh;
  302. struct LabelText *The_Text;
  303. {
  304.  BYTE IDBuffer[5];
  305.  int back, ok;
  306.  LONG LongBuffer;
  307.  LONG LabelTextSize;
  308.  
  309.  back =0;
  310.  LabelTextSize = sizeof( struct LabelText) -12;
  311.  if ( The_Text != NULL)
  312.    {
  313.     strcpy( IDBuffer, "LMTC");
  314.     if (( ok= Write( fh, IDBuffer, 4L)) == 4)
  315.       {
  316.        LongBuffer =  LabelTextSize;
  317.        if (( ok= Write( fh, &LongBuffer, 4L)) == 4)
  318.          {
  319.           ok = Write( fh, The_Text, LabelTextSize);
  320.           if ( ok == LabelTextSize)
  321.             {
  322.              back = 1;
  323.             }
  324.          }
  325.       }
  326.    }
  327.  return( back);
  328. }
  329.  
  330.  
  331.